import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter_echarts/flutter_echarts.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/log_utils.dart';
import 'package:yt_devops/pages/devices/device_tab/device_detail/new_air_cooling_page/temperature_full_chart/component/full_screen_back.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'es_power_statistics_fullscreen_chart_controller.dart';

class EsPowerStatisticsFullscreenChartPage extends GetView<EsPowerStatisticsFullscreenChartController> {
    const EsPowerStatisticsFullscreenChartPage({Key? key}) : super(key: key);

    @override
    Widget build(BuildContext context) {
    return   SafeArea(

        child:
        RotatedBox(
            quarterTurns: 1,
            child:Scaffold(
                backgroundColor: Colors.white,
                body: Column(
                    children: [
                        // Gaps.vGap10,
                        FullScreenBack(() {
                            Log.d('back');
                            Get.back();
                        }),
                        Expanded(
                            child: Container(
                                color: Colors.white,
                                padding: EdgeInsets.only(left: 0,right: 0),
                                child: Echarts(
                                    captureAllGestures: false,
                                    option: '''
 {
  color: ['#3DD598', '#007DFF'],
  /// 横轴
  xAxis: {
    type: 'category',                
    axisLine:{
      show: false,
    }, 
    
    axisTick: {
      show: false
    }, 
    axisLabel: {
      color: '#999999',
      fontSize: 11,
      interval: function (index) { // 自定义间隔函数 
          if (index % 4 === 0) { // 每四小时显示一次  // 返回值是五分钟为一个间隔
              return true;
          } else {
              return false;
          }
      },
    },
  },
  yAxis: [
  
    {
      type: 'value',
      name:  'kWh',
      nameTextStyle: {
        align: "center"
      },
      align: 'left',
      padding: [3, 4, 5, 6],
      verticalAlign: 'top',
      nameLocation: 'end',
      position: 'left',
      splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
    },
    {
      type: 'value',
      name:  ${jsonEncode(ResKey.yuan.tr)},
       nameTextStyle: {
        align: "center"
      },
      nameLocation: 'end',
      splitLine: {
        lineStyle: {
          type: 'dashed', //虚线
        },
      },
    },
  ],
  grid: {
    top: 30,
    bottom: 110,
    right: 40,
    left: 40,
  },
  legend: {
    show: true,
    icon: 'rect',
        left:20,
    right:20,
    top:'260',
        itemHeight: 3,
    itemWidth: 12,
     textStyle: {
      borderRadius: [2, 2, 2, 2]
    },
    padding: [
    0,  // 上
    0, // 右
    0,  // 下
    0, // 左
]
  },
  tooltip: {
    trigger: 'axis',
    backgroundColor: 'rgba(0,0,0,0.85)',
    borderWidth: 0,
    opacity: 0.2,
    confine: true,
    padding: [
      10, // 上
      8, // 右
      10, // 下
      8 // 左
    ],
    textStyle: {
      color: 'white'
    },
  },
  dataZoom: [
    // {
    //   type: 'inside',
    //   realtime: false,
    // },
    // {
    //   start: 0,
    //   end: 100,
    //   height: 15,
    //   realtime: false,
    // },
  ],
  series: [

    {
      name: ${jsonEncode(controller.paramList[0])},
      color: '#5D7092',
      type: 'bar',
      yAxisIndex: 0,
      data: ${jsonEncode(controller.chargePower)},
    },
    {
      name: ${jsonEncode(controller.paramList[1])},
      color: '#FAC958',
      type: 'bar',
      yAxisIndex: 0,
      data: ${jsonEncode(controller.dischargePower)},
    },
    {
      name: ${jsonEncode(controller.paramList[2])},
      color: '#67D7FC',
      type: 'bar',
      yAxisIndex: 1,
      data: ${jsonEncode(controller.profit)},
    },
  
  ],
}

  ''',
                                ),
                            ))
                    ],
                ),
            ),
        ));
    }
}
